#include<stdio.h>
#define FILEINP "CHIAKEO.INP"
#define FILEOUT "CHIAKEO.OUT"
long i,j,n,a[10001],sum[100000001]={0},max,c,ctemp,mark[100000001]={0},next;
void input(){
    FILE *fp=fopen(FILEINP,"r");
    fscanf(fp,"%ld",&n);
    for(i=1;i<=n;i++){
        fscanf(fp,"%ld",&a[i]);
        max+=a[i];
    }
    fclose(fp);
}
void init(){
    c=0;ctemp=0;
    for(i=1;i<=max/2;i++)sum[i]=-1;
    for(i=1;i<=n;i++){
        for(j=1;j<=c;j++){
            if(sum[j]!=-1 && j+a[i]<=max/2){
                sum[j+a[i]]=j;
                mark[j+a[i]]=i;
                if(ctemp<j+a[i])ctemp=j+a[i];
            }
        }
        sum[a[i]]=0;
        mark[a[i]]=i;
        if(a[i]<=max/2 && ctemp<a[i])ctemp=a[i];
        c=ctemp;
    }
}
void print(){
    FILE *fp=fopen(FILEOUT,"w");
    fprintf(fp,"Nguoi 1 : %ld vien, nguoi 2 : %ld vien",c,max-c);
    fprintf(fp,"\n\nNguoi 1 :");
    while(c>0){
        next=sum[c];
        fprintf(fp,"\t%ld",c-next);
        a[mark[c]]=-1;
        c=next;
    }
    fprintf(fp,"\nNguoi 2 :");
    for(i=1;i<=n;i++)if(a[i]!=-1)fprintf(fp,"\t%ld",a[i]);
    fclose(fp);
}
int main(){
    input();
    init();
    print();
    return 0;
}
